Version 1.0 (07 August 2017)
What to know?
What to bring?
Which R packages to install/load?
pkg <- c("ggplot2", "rmarkdown", "knitr", "dplyr");
lapply(pkg, function(x) { if (!require(x, character.only = TRUE, quietly = TRUE)) {
install.packages(x);
require(x, quietly = TRUE)}
})
What data to work with?
We will use the starwars dataset from dplyr.
head(starwars, n = 4);
## # A tibble: 4 x 13 ## name height mass hair_color skin_color eye_color birth_year ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> ## 1 Luke Skywalker 172 77 blond fair blue 19.0 ## 2 C-3PO 167 75 <NA> gold yellow 112.0 ## 3 R2-D2 96 32 <NA> white, blue red 33.0 ## 4 Darth Vader 202 136 none white yellow 41.9 ## # ... with 6 more variables: gender <chr>, homeworld <chr>, species <chr>, ## # films <list>, vehicles <list>, starships <list>
3. Specifiy output option
Exercise: Create a new R Markdown document in RStudio
A note on different Markdown flavours: GitHub, R Markdown, vanilla Markdown, …
…
<img src="path/to/image.png" style="width:200px;">knitr::include_graphicsExercise: Create different output documents
More details for every output option
Exercise: Show different chunk options
knitr::kable()DT::datatableExcercise: Output a table
knitr::kable()suppressMessages(library(knitr)); kable(starwars[1:4, 1:4])
| name | height | mass | hair_color |
|---|---|---|---|
| Luke Skywalker | 172 | 77 | blond |
| C-3PO | 167 | 75 | NA |
| R2-D2 | 96 | 32 | NA |
| Darth Vader | 202 | 136 | none |
DT::datatable()suppressMessages(library(DT)); #DT::datatable(starwars, options = list(dom = "ftp", scrollX = TRUE, pageLength = 4)); DT::datatable(starwars[, 1:4], options = list(pageLength = 8));
Load the necessary libraries:
suppressMessages(library(ggplot2)); suppressMessages(library(plotly));
## Warning: package 'plotly' was built under R version 3.4.1
suppressMessages(library(scatterD3));
plotly::ggplotly()ggplotly(ggplot(starwars, aes(x = height, y = mass, label = name)) + geom_point(), height = 5);
scatterD3::scatterD3()scatterD3(x = starwars$height, y = starwars$mass, lab = starwars$name);
R Markdown and shiny
…